import 'package:flutter/material.dart';
import 'package:flutter_base_framework/base_framework_export.dart';
import 'package:flutter_http_utils/flutter_http_utils.dart';
import 'package:flutter_base_app/generated/assets.dart';
import 'package:flutter_base_app/widgets/image/svg_widget.dart';

import 'app_colors.dart';
import 'theme.dart';
import '../widgets/app_bar/custom_app_bar.dart';
import '../widgets/base/app_bg.dart';

class BaseFramework {
  BaseFramework._();

  static BoxDecoration get defaultBoxDecoration => BoxDecoration(
    gradient: LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: [
        ColorsApp.page_background,
        ColorsApp.page_background,
      ],
    ),
  );

  static void init() {
    BaseCoreConfig.createMainWidgetRoot = (BaseState baseState, BuildContext context) => AppBgWidget(
      // color: baseState.backgroundColor(context),
      decoration: defaultBoxDecoration,
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: baseState.createAppbar(),
        floatingActionButton: baseState.floatingActionButton(),
        //输入法弹出时，页面不要缩放
        resizeToAvoidBottomInset: baseState.resizeToAvoidBottomInset,
        //将主体延伸到AppBar后面
        extendBodyBehindAppBar: baseState.extendBodyBehindAppBar,
        extendBody: true,
        body: baseState.buildWidget(context),
      ),
    );
    //创建默认的AppBar
    BaseCoreConfig.createAppbar = (BaseState baseState, BuildContext context) => baseState.createDefaultAppbar();
    BaseCoreConfig.defaultLoadStateLayoutIcon = (BuildContext context, ContextData contextData) => SvgWidget(
      Assets.svgMaterialServiceError,
      width: contextData.imgWidth,
      height: contextData.imgHeight,
    );
    BaseCoreConfig.onDispose = (obj) {
      CancelTokenManage.cancel(obj);
    };
  }
}
